<?php
class settings {

	public $data;

	public function __construct(){
		global $db;

		$db->query("SELECT `settings_name`, `settings_value` FROM `" . SETTINGS_TABLE . "`");
		foreach($db->fetch_assoc() as $item){

			$this->data[$item['settings_name']] = $item['settings_value'];

		}

	}

	public function __set($name, $value){
		global $db;

		$value = $db->real_escape_string($value);

		$db->query("INSERT INTO `" . SETTINGS_TABLE . "` (`settings_name`, `settings_value`) VALUE ('{$name}', '{$value}') ON DUPLICATE KEY UPDATE `settings_value` = '{$value}'");

	}

	public function __get($name){
		global $db;
		$sql = "SELECT `settings_value` FROM `" . SETTINGS_TABLE . "` WHERE `settings_name` = '{$name}'";
		if($db->query($sql) && $db->affected_rows())
		{
			list($row) = $db->fetch_field('settings_value');
			return $row;
		}
		return false;
	}

	public function __isset($key)
	{
	    return isset($this->data[$key]);
	}
}
?>